import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Demo31 {
/**
 * @param args
 * @throws InterruptedException
 */
public static void main(String[] args) throws InterruptedException {
    BlockingQueue<Integer> queue = new LinkedBlockingQueue<>(1000);

    Thread producer=new Thread(()->{
        int count =0;
        try{
        while(true){
            queue.put(count);
            System.out.println("添加一个元素"+count);
            count++;
            Thread.sleep(1000);
        }
    }catch(InterruptedException e){
        e.printStackTrace();
    }
    });
    Thread consumer=new Thread(()->{
        try {
            while(true){
                System.out.println("消费一个元素"+queue.take());

            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    producer.start();
    consumer.start();
    producer.join();
    consumer.join();
}
}
